#include "cfam.h"

/**
  \brief definit les champ du message
  */
#define TFM_DEST_ADDR_LSB_IDX   0
#define TFM_DEST_ADDR_MSB_IDX   1
#define TFM_FAM_IDX             2
#define TFM_CMD_IDX             3
#define TFM_LEN_IDX             4
#define TFM_START_PAYLOAD_IDX   5


CFam::CFam()
{
}

TFMsg CFam::formatMsg( unsigned short i_dest_addr, unsigned char i_fam_id, unsigned char i_cmd_id,
                    unsigned char i_len, unsigned char *ip_payload )
{
    TFMsg lo_msg;
    unsigned char loop;

    lo_msg.msg[TFM_DEST_ADDR_LSB_IDX] = i_dest_addr & 0xFF;
    lo_msg.msg[TFM_DEST_ADDR_MSB_IDX] = i_dest_addr >> 8;
    lo_msg.msg[TFM_FAM_IDX] = i_fam_id;
    lo_msg.msg[TFM_CMD_IDX] = i_cmd_id;
    lo_msg.msg[TFM_LEN_IDX] = i_len;
    for( loop=0; loop<i_len; loop++ )
    {
        lo_msg.msg[TFM_START_PAYLOAD_IDX+loop] = ip_payload[loop];
    }

    lo_msg.size = TFM_START_PAYLOAD_IDX + i_len;

    return lo_msg;
}

QString CFam::getAppName( unsigned char i_app_id )
{
    QString lo_str;

    switch( i_app_id )
    {
        case APP_BOOTLOADER:
        {
            lo_str = "Bootloader";
        }
        break;

        case APP_BRIDGE_UART:
        {
            lo_str = "Bridge Uart";
        }
        break;

        case APP_RX_2_WAY:
        {
            lo_str = "Rx 2 Servo";
        }
        break;

        default:
        {
            lo_str = QString::number(i_app_id, 16 ).toUpper();
        }
        break;
    }

    return lo_str;
}
